//
//  EmoticonViewModel.swift
//  01-表情键盘
//
//  Created by 陈伟 on 15/10/25.
//  Copyright © 2015年 陈伟. All rights reserved.
//

import Foundation

class EmoticonManager {
    
    static let sharedManager = EmoticonManager()
    var emoticonList = [EmoticonGroupModel]()
    
    init() {
//                    print("zhelizheli")
        emoticonList.append(EmoticonGroupModel(dict: ["group_name_cn": "最近"]))
        
        let path = NSBundle.mainBundle().pathForResource("emoticons.plist", ofType: nil, inDirectory: "Emoticons.bundle")
        let dirDict = NSDictionary(contentsOfFile: path!) as! [String: AnyObject]
        
        let array = dirDict["packages"] as! [[String: AnyObject]]
        
        var groupName = [String]()
        
        for d in array {
           let name = d["id"] as! String
            groupName.append(name)
        }
        
        //加载info.plist 
        //路径 = Emoticons.bundle+groupName
        for name in groupName {
            let dPath = "Emoticons.bundle/" + name
//            print(dPath)
            let newPath = NSBundle.mainBundle().pathForResource("info.plist", ofType:nil , inDirectory: dPath)
            let dict = NSDictionary(contentsOfFile: newPath!) as! [String: AnyObject]
            
            let emoticonGroup =  EmoticonGroupModel(dict: dict)
            
            emoticonList.append(emoticonGroup)
        }
    }
}